package com.xxx.modules.sys.controller;

import com.xxx.common.utils.R;
import com.xxx.modules.sys.domain.SysUserDomain;
import com.xxx.modules.sys.service.SysUserService;
import com.xxx.modules.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/** 用户注册 Controller
 * Created by Administrator on 2017/10/13.
 */
public class SysUserRegisterController {

    @Autowired
    private UserService userService;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 用户注册
     * @param sysUserDomain
     * @param kaptcha
     * @return
     */
    @RequestMapping(value = "sys/user/register",method = RequestMethod.POST)
    public R userRegister(SysUserDomain sysUserDomain,String kaptcha){
        //tip  验证码判断似乎放在前端判断更好
        sysUserService.add(sysUserDomain);
        return R.ok();
    }

    /**
     * 查询该用户名是否已经存在
     * @param username
     * @return
     */
    @RequestMapping(value = "sys/user/queryUserName",method = RequestMethod.POST)
    public R queryUsername(String username){
        SysUserDomain userDomain = userService.queryUserByUserName(username);
        if(userDomain!=null){
            return R.ok().put("state",1);//状态码为1  表示该用户名已存在
        }
        return R.ok().put("state",0);//状态码为0  标识该用户名不存在
    }

    @RequestMapping(value = "sys/user/queryEmail",method = RequestMethod.POST)
    public R queryEmail(String email){
        SysUserDomain userDomain = userService.queryUserByEmail(email);
        if(userDomain!=null){
            return R.ok().put("state",1);//状态码为1  表示该用户名已存在
        }
        return R.ok().put("state",0);//状态码为0  标识该用户名不存在
    }

}
